@extends('base.base')
@section('base')
    <!-- 内容区域 -->
    <div class="main-panel">
        <div class="content-wrapper">
            <div class="page-header">
                <h3 class="page-title">
                     <span class="page-title-icon bg-gradient-primary text-white mr-2">
                        <i class="mdi mdi-settings"></i>
                    </span>
                    订单管理
                </h3>
                <nav aria-label="breadcrumb">
                    <ol class="breadcrumb">
                        <li class="breadcrumb-item"><a href="#">订单管理</a></li>
                        <li class="breadcrumb-item active" aria-current="page">订单列表</li>
                    </ol>
                </nav>
            </div>
            <div class="row">
                <div class="col-lg-12 grid-margin stretch-card">
                    <div class="card">
                        <div class="card-body">
                            <h4 class="card-title">商品列表</h4>
                            <div class="col-lg-9" style="float: left;padding: 0;">
                                <button type="button" class="btn btn-sm btn-gradient-success btn-icon-text" onclick="exports()">
                                    <i class="mdi mdi-plus btn-icon-prepend"></i>
                                    导出订单
                                </button>
                            </div>
                            <div class="col-lg-9" style="float: left;padding: 0;">
                                <button type="button" class="btn btn-sm btn-gradient-success btn-icon-text" onclick="imports()">
                                    <i class="mdi mdi-plus btn-icon-prepend"></i>
                                    导入发货
                                </button>
                            </div>
                            <div class="col-lg-3" style="float: right">
                                <form action="">
                                    <div class="form-group" >
                                        <div class="input-group col-xs-3">
                                            <input type="text" name="wd" class="form-control file-upload-info" placeholder="请输入关键字:姓名,电话,订单编号" value="{{ $wd }}">
                                            <span class="input-group-append">
                                                <button class=" btn btn-sm btn-gradient-primary" type="submit"><i class="mdi mdi-account-search btn-icon-prepend"></i>
                                                    搜索
                                                </button>
                                            </span>
                                        </div>
                                    </div>
                                </form>
                            </div>
                            <table class="table table-bordered">
                                <thead>
                                <tr>
                                    <th width="10%">订单号</th>
                                    <th width="10%">用户昵称</th>
                                    <th width="25%">商品信息</th>
                                    <th width="10%">实际支付</th>
                                    <th width="10%">支付状态</th>
                                    <th width="10%">订单状态</th>
                                    <th width="10%">下单时间</th>
                                    <th width="15%">操作</th>
                                </tr>
                                </thead>
                                <tbody>
                                @foreach($list as $k=>$v)
                                    <tr>
                                        <td>{{ $v->order_id }}</td>
                                        <td>{{$v->real_name}}</td>

                                        <td>
                                        @foreach($v->info as $ke=>$val)
                                                <br>{{ $val['cart_info']['productInfo']['store_name']}}<br>
                                        @endforeach
                                        </td>
                                        <td>{{ $v->pay_price }}</td>
                                        <td>
                                            @if($v->paid == 1)
                                                @if($v->pay_type == 'weixin')
                                                    微信支付
                                                @elseif($v->pay_type == 'yue')
                                                    余额支付
                                                @elseif($v->pay_type == 'offline')
                                                    线下支付
                                                @else
                                                    其他支付
                                                @endif
                                            @else
                                                @if($v->pay_type == 'offline')
                                                    线下支付
                                                @else
                                                    未支付
                                                @endif
                                            @endif
                                        </td>
                                        <td>
                                            {{$v->status_name}}
                                        </td>
                                        <td>{{ date('Y-m-d H:i:s' , $v->add_time) }}</td>
                                        <td>
                                            @if($v->operate_status == 1)
                                                <button type="button" class="btn btn-sm btn-gradient-danger btn-icon-text" onclick="editView({{ $v->id }})">
                                                    <i class="mdi mdi-delete btn-icon-prepend"></i>
                                                    修改订单
                                                </button>
                                            @elseif($v->operate_status == 2)
                                                <button type="button" class="btn btn-sm btn-gradient-danger btn-icon-text" onclick="deliveryView({{ $v->id }})">
                                                    <i class="mdi mdi-delete btn-icon-prepend"></i>
                                                    我要发货
                                                </button>
                                            @elseif($v->operate_status == 4)
                                                <button type="button" class="btn btn-sm btn-gradient-danger btn-icon-text" onclick="take_delivery({{ $v->id }})">
                                                    <i class="mdi mdi-delete btn-icon-prepend"></i>
                                                    确认收货
                                                </button>
                                            @endif
                                           <div class="click-btn">
                                           <a href="javascript:void(0);" onclick="detail({{ $v->id }})">详情>></a>
                                            <a href="javascript:void(0);" onclick="mark({{ $v->id }})">备注>></a>
                                            <a class="bottom" href="javascript:void(0);" onclick="log({{ $v->id }})">记录>></a>
                                            <!-- <a href="12313"></a> -->

                                            <!-- <div></div> -->
                                            <!-- <button type="button" class="btn btn-sm btn-gradient-dark btn-icon-text" onclick="detail({{ $v->id }})">
                                                详情
                                                <i class="mdi mdi-file-check btn-icon-append"></i>
                                            </button>
                                            <button type="button" class="btn btn-sm btn-gradient-dark btn-icon-text" onclick="mark({{ $v->id }})">
                                                备注
                                                <i class="mdi mdi-file-check btn-icon-append"></i>
                                            </button>
                                            <button type="button" class="btn btn-sm btn-gradient-dark btn-icon-text" onclick="log({{ $v->id }})">
                                                记录
                                                <i class="mdi mdi-file-check btn-icon-append"></i>
                                            </button> -->
                                                @if($v->paid == 1)
                                                <a class="bottom" href="javascript:void(0);" onclick="refundViwe({{ $v->id }})">退款>></a>
                                            <!-- <button type="button" class="btn btn-sm btn-gradient-dark btn-icon-text" onclick="refundViwe({{ $v->id }})">
                                                退款
                                                <i class="mdi mdi-file-check btn-icon-append"></i>
                                            </button> -->
                                                @endif
                                           </div>
                                        </td>
                                    </tr>
                                @endforeach
                                </tbody>
                            </table>
                            <div class="box-footer clearfix">
                                总共 <b>{{ $appends_wd->appends(["wd"=>$wd])->total()  }}</b> 条,分为<b>{{ $appends_wd->lastPage() }}</b>页
                                {!! $appends_wd->links() !!}
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <style>
        .click-btn{
            padding: 5px 1px;
            display: flex;
            flex-wrap: wrap;
            justify-content: space-between;
            align-items: center;
        }
        .click-btn a{
            width: 50%;
        }
        .bottom{
            margin-top:2px;
        }
    </style>
    <script>
        $(function(){
            cutStr(50);
        });
        // 订单导出
        function exports(){
            window.location.href="{{url('/admin/order/import')}}"
        }

        function imports(){
            var page = layer.open({
                type: 2,
                title: '发货',
                shadeClose: true,
                shade: 0.8,
                area: ['70%', '90%'],
                content: '/admin/order/import'
            });
        }


        function editView(id){
            var page = layer.open({
                type: 2,
                title: '修改订单',
                shadeClose: true,
                shade: 0.8,
                area: ['70%', '90%'],
                content: '/admin/order/edit?id='+id
            });
        }
        function deliveryView(id){
            var page = layer.open({
                type: 2,
                title: '发货',
                shadeClose: true,
                shade: 0.8,
                area: ['70%', '90%'],
                content: '/admin/order/delivery?id='+id
            });
        }
        function refundViwe(id){
            var page = layer.open({
                type: 2,
                title: '退款',
                shadeClose: true,
                shade: 0.8,
                area: ['70%', '90%'],
                content: '/admin/order/refund?id='+id
            });
        }
        function detail(id){
            var page = layer.open({
                type: 2,
                title: '详情',
                shadeClose: true,
                shade: 0.8,
                area: ['70%', '90%'],
                content: '/admin/order/detail?id='+id
            });
        }
        function mark(id){
            var page = layer.open({
                type: 2,
                title: '备注',
                shadeClose: true,
                shade: 0.8,
                area: ['70%', '90%'],
                content: '/admin/order/mark?id='+id
            });
        }
        function log(id){
            var page = layer.open({
                type: 2,
                title: '详情',
                shadeClose: true,
                shade: 0.8,
                area: ['70%', '90%'],
                content: '/admin/order/log?id='+id
            });
        }
        function del(id){
            myConfirm("删除操作不可逆,是否继续?",function(){
                myRequest("/admin/product/delete?id="+id,"post",{},function(res){
                    layer.msg(res.msg)
                    setTimeout(function(){
                        window.location.reload();
                    },1500)
                });
            });
        }

        // 确认收货
        function take_delivery(id){
            var data = {id: id};
            myRequest("/admin/order/take_delivery","post",data,function(res){
                layer.msg(res.msg)
            });
        }

        $('.menu-switch').click(function(){
            id = $(this).attr('id');
            state = $(this).attr('state');
            console.log(id)
            console.log(state)
            if(state == "on"){
                $('.pid-'+id).hide();
                $(this).attr("state","off")
                $(this).removeClass('mdi-menu-down').addClass('mdi-menu-right');
            }else{
                $('.pid-'+id).show();
                $(this).attr("state","on")
                $(this).removeClass('mdi-menu-right').addClass('mdi-menu-down');
            }
        })
    </script>
@endsection
